<?php
require 'connect/connect.php';
$page = 'main_forum';
include_once 'header.php';
$tbl_name = "forum_question";
extract($_POST);
if (isset($_GET['id'])) {
    $id = $_GET['id'];
}


$sql = "SELECT * FROM $tbl_name WHERE id='$id'";
$result = mysql_query($sql);

$rows = mysql_fetch_array($result);
?>

<a href="main_forum.php" style="padding-right: 100px; font-weight: bold; text-decoration: none"> &LT;&LT; Back </a><a style="font-weight: bold; text-decoration: none" href="create_topic.php">Create New </a>
<!--<strong><?php echo $rows['topic'] . " (" . $rows['datetime'] . ")"; ?></strong><br/>-->
<p style="font-weight: bold"><?php echo $rows['detail']; ?></p>
<?php
$tbl_name2 = "forum_answer"; // Switch to table "forum_answer"

$sql2 = "SELECT * FROM $tbl_name2 WHERE question_id='$id'";
$result2 = mysql_query($sql2);

while ($rows = mysql_fetch_array($result2)) {
    ?>
    <p style="border-bottom-color: #444444;border-bottom-style: dotted; border-bottom-width: thin; font-style: italic">
    <?php echo $rows['a_answer']; ?><?php echo " (" .$rows['a_name'].  " ".$rows['a_datetime'] . ")"; ?></p>

    <?php
}

$sql3 = "SELECT view FROM $tbl_name WHERE id='$id'";
$result3 = mysql_query($sql3);

$rows = mysql_fetch_array($result3);
$view = $rows['view'];

if (empty($view)) {
    $view = 1;
    $sql4 = "INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'";
    $result4 = mysql_query($sql4);
}

$addview = $view + 1;
$sql5 = "update $tbl_name set view='$addview' WHERE id='$id'";
$result5 = mysql_query($sql5);

mysql_close();
?>
<form name="form1" method="post" action="add_answer.php" >
    <table style="width: 99%">
        <tr><th colspan="2">Enter Comment: </th></tr>
        <tr><td colspan="2"><textarea name="a_answer" style="width: 99%" rows="4" id="a_answer"/></textarea><input name="id" type="hidden" value="<?php echo $id; ?>"/></td></tr>
        <tr><td><input type="submit" name="Submit" value="Submit"/></td><td> <input type="reset" name="Submit2" value="Reset"/></td></tr>
    </table>
</form>

<?php include_once 'footer.php'; ?>